package lc.回溯;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/9/5
 */
public class Math77 {

    List<List<Integer>> result = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();
    public List<List<Integer>> combine(int n, int k) {
        dfs(n,k,1);
        return result;
    }


    private void dfs(int n, int k, int index) {
        if(k == path.size()) {
            result.add(new ArrayList<>(path)); // 收集结果
            return;
        }
        for (int i = index; i <= n; i++) {
            path.add(i);
            dfs(n,k,i+1);
            path.removeLast(); // lc.回溯
        }
    }
}
